package cate.game.db.mongo.cfg;

import cate.common.game.GameCollection;
import cp.solution.define.SrvType;
import cate.game.display.po.HeroDisplay;
import cate.game.play.proce.play.PlayPO;
import cate.game.status.GameStatus;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

@NoteClass("mongo自动删除config")
public class AutoDeleteConfig {

	@NoteField("集合名")
	public String collection;

	@NoteField("字段名")
	public String field;

	@NoteField("过期时间")
	public long expireAfter = 1L;

	@NoteField("过期时间单位")
	public TimeUnit timeUnit = TimeUnit.SECONDS;

	public static AutoDeleteConfig build( String collection, String field, long expireAfter, TimeUnit timeUnit) {
		AutoDeleteConfig item = new AutoDeleteConfig();
		item.collection = collection;
		item.field = field;
		item.expireAfter = expireAfter;
		item.timeUnit = timeUnit;
		return item;
	}

	public static AutoDeleteConfig build( String collection, String field) {
		return build(collection, field, 1L, TimeUnit.SECONDS);
	}


	public static List<AutoDeleteConfig> ALL;
	private static AutoDeleteConfig[] GAME_SERVER;
	private static AutoDeleteConfig[] CROSS = new AutoDeleteConfig[] {

	};
	private static AutoDeleteConfig[] GROUP = new AutoDeleteConfig[] {

	};
	public static AutoDeleteConfig[] find(SrvType srvType) {
		switch (srvType) {
			case cross:
				return CROSS;
			case group:
				return GROUP;
			case game:
				return GAME_SERVER;
			default:
				return null;
		}
	}

	static {
		ALL = new ArrayList<>();
		ALL.add(AutoDeleteConfig.build(GameCollection.NAME_PLAY, PlayPO.AUTO_DELETE_FIELD));
		ALL.add(AutoDeleteConfig.build(GameCollection.NAME_HERO_DISPLAY, HeroDisplay.AUTO_DELETE_FIELD));
		ALL.add(AutoDeleteConfig.build(GameCollection.NAME_STATUS, GameStatus.AUTO_DELETE_FIELD, 7L, TimeUnit.DAYS));

		GAME_SERVER = new AutoDeleteConfig[] {
				AutoDeleteConfig.build(GameCollection.NAME_PLAY, PlayPO.AUTO_DELETE_FIELD),
				AutoDeleteConfig.build(GameCollection.NAME_HERO_DISPLAY, HeroDisplay.AUTO_DELETE_FIELD),
				AutoDeleteConfig.build(GameCollection.NAME_STATUS, GameStatus.AUTO_DELETE_FIELD, 7L, TimeUnit.DAYS)};
	}
}
